﻿@model Cxuu.Models.EditAdminUserPost
@{
    ViewData["Title"] = "保存";
}

<div class="content-top-nav">
    <div class="layui-row">
        <div class="layui-col-md11">
            <h3 style="color:#444">
                <i class="layui-icon layui-icon-home"></i>
                岗位编辑
            </h3>
        </div>
        <div class="layui-col-md1" style="text-align:right;">
            <button class="layui-btn layui-btn-sm" onclick="loadMain('/Admin/UserPost/')">返回列表</button>
        </div>
    </div>
    <hr>
</div>

<div class="layui-fluid" style="margin-bottom:50px;">
    <div class="layui-form">
        <form class="layui-form" action="" lay-filter="FormEdit" enctype="multipart/form-data">
            <div class="layui-form-item">
                <label asp-for="PostName" class="layui-form-label required"></label>
                <div class="layui-input-inline">
                    <input type="text" asp-for="PostName" lay-verify="required" lay-reqtext="岗位名称不能为空" placeholder="请输入岗位名称" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label asp-for="PostCode" class="layui-form-label required"></label>
                <div class="layui-input-inline">
                    <input type="text" asp-for="PostCode" id="PostCode" lay-verify="required" lay-reqtext="岗位代码不能为空" placeholder="请输入岗位代码" value="" class="layui-input" disabled>
                </div>
                <div>
                    <button type="button" class="layui-btn layui-btn-primary" lay-active="e1">@AdminPostConst.SUPREME (单位最高领导)</button>
                    <button type="button" class="layui-btn layui-btn-primary" lay-active="e2">@AdminPostConst.MASTER (部门级负责人)</button>
                    <button type="button" class="layui-btn layui-btn-primary" lay-active="e3">@AdminPostConst.DEPUTY (副职)</button>
                    <button type="button" class="layui-btn layui-btn-primary" lay-active="e4">@AdminPostConst.WORKER (民警)</button>
                    <button type="button" class="layui-btn layui-btn-primary" lay-active="e5">@AdminPostConst.OTHER (自定义)</button>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required"></label>
                <div class="layui-input-block">
                    <div class="layui-form-mid layui-word-aux">supreme全部资源权限，master所在部门最高权限，deputy具有一定特殊权限，police不具有特殊权限有本级部门一般权限，other为个人资源权限</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label asp-for="Sort" class="layui-form-label required"></label>
                <div class="layui-input-inline">
                    <input type="text" asp-for="Sort" value="" class="layui-input" lay-verify="required|number">
                </div>
                <div class="layui-form-mid layui-word-aux">只能填写数字，如： 2</div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label asp-for="Remark" class="layui-form-label"></label>
                <div class="layui-input-block">
                    <textarea name="Remark" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="saveBtn" id="saveBtn"><i class="layui-icon">&#xe605;</i>@ViewData["Title"]</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    layui.define(function () {
        var form = layui.form, layer = layui.layer, $ = layui.jquery, util = layui.util;

        var editId = @ViewBag.id+1;
        if (editId > 1) {
            $.getJSON("/Admin/UserPost/AddOrEdit?id=@ViewBag.id&edit=1", function (res) {
                if (res.status == 1) {
                    form.val('FormEdit', {
                        Id: res.data.id,
                        PostName: res.data.postName,
                        PostCode: res.data.postCode,
                        Remark: res.data.remark,
                        Sort: res.data.sort,
                    });
                }
            })
        }
        form.render();


        util.event('lay-active', {
            e1: function (othis) {
                $("#PostCode").val("@AdminPostConst.SUPREME");
            }
            , e2: function (othis) {
                $("#PostCode").val("@AdminPostConst.MASTER");
            }
            , e3: function (othis) {
                $("#PostCode").val("@AdminPostConst.DEPUTY");
            }
            , e4: function (othis) {
                $("#PostCode").val("@AdminPostConst.WORKER");
            }
            , e5: function (othis) {
                $("#PostCode").val("@AdminPostConst.OTHER");
            }
        });

        var dataPost = function (url, data) {
            $.post(url, data, function (res) {
                if (res.status == 1) {
                    $("#saveBtn").hide();
                    layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                        loadMain('/Admin/UserPost/Index/' + res.cid);
                    });
                } else {
                    layer.msg(res.msg, { icon: 2, anim: 6, time: 5000 });
                }
            });
        }

        $('#saveBtn').click(function () {
            var field = form.val('FormEdit');
            if (!field.Sort) {
                layer.msg('排序必须填写且为数字');
                return false;
            };
            if (editId == 1)
                dataPost('/Admin/UserPost/CreatePost', form.val('FormEdit'));
            else
                dataPost('/Admin/UserPost/EditPost?id=@ViewBag.id', form.val('FormEdit'));
            return false;
        });
    });

</script>